package pl.mess.core.actions;

import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.xwork.ActionSupport;
import pl.mess.core.uiobjects.MESSTreeView;
import pl.mess.core.uiobjects.MESSTreeViewElement;
import pl.mess.core.uiobjects.MESSNewsEntry;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.Date;
import java.sql.Timestamp;

/**
 * Created by IntelliJ IDEA.
 * User: gibffe
 * Date: Mar 10, 2006
 * Time: 2:23:44 PM
 * To change this template use File | Settings | File Templates.
 */
public class LoadStartPage extends ActionSupport implements ServletRequestAware {

    private HttpServletRequest request = null;

    private String page = null;
    

    public String execute() throws Exception {
      
        // prepare tree for testing
        MESSTreeView tree = new MESSTreeView();

            MESSTreeViewElement e2 = new MESSTreeViewElement();
            e2.setElementName("element 2");
                MESSTreeViewElement e3 = new MESSTreeViewElement();
                e3.setElementName("eee 333");
                e3.setNodeDescription("ea lsdllds dslf");
                    e3.addElement(new MESSTreeViewElement());
                    e3.addElement(new MESSTreeViewElement());

                e2.addElement(e3);
                e2.addElement(new MESSTreeViewElement());
                e2.addElement(new MESSTreeViewElement());
                MESSTreeViewElement ee = new MESSTreeViewElement();
                ee.setElementName("certificate");
                ee.setNodeDescription("certificate 22 3322");
                e2.addElement(ee);

        tree.addElement(e2);
        this.request.setAttribute("treeData", tree);

        // prepare news view for testing
        List<MESSNewsEntry> newsList = new ArrayList<MESSNewsEntry>();
        MESSNewsEntry e1 = new MESSNewsEntry();
                      e1.setEntryDate(new Timestamp(new Date().getTime()));
                      e1.setTitle("test title");
                      e1.setHeader("test header");
                      e1.setContent("test content");
                      e1.setAuthor("gibffe");
        //newsList.add(e1);

        this.request.setAttribute("adminNews", newsList);
        
        return "success";
    }

    public void setServletRequest(HttpServletRequest httpServletRequest) {
        this.request = httpServletRequest;
    }


    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }
}
